package com.sanploy.fed.push.dao;


import com.sanploy.fed.push.bean.NewsClass;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016/8/1.
 */
@Repository
@Transactional
public interface NewsClassDao  extends CrudRepository<NewsClass,Long> {

    @Query(value = "SELECT * FROM newsclass WHERE parentid = ?",nativeQuery = true)
    public List<NewsClass> findByParentId(Long parentId);

    @Query(value = "SELECT * FROM newsclass WHERE parentid = ? AND name=?",nativeQuery = true)
    public List<NewsClass> findByNameAndParent(Long parentid,String name);

    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE newsclass SET name = ? where id = ?",nativeQuery = true)
    public void setNameById(String name,Long id);
}
